<template lang="">
  <div class="user">
    <el-card shadow="always">
      <div slot="header">
        注册用户列表
      </div>
      <el-table :data="list" border stripe>
        <el-table-column type="index" label="#" align="center" width="75" fixed="left" />
        <el-table-column label="用户名" prop="username" align="center" width="150" />
        <el-table-column label="头像" prop="icon" align="center" width="150">
          <template slot-scope="scope">
            <el-avatar :size="60" :src="scope.row.icon">
              <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png">
            </el-avatar>
          </template>
        </el-table-column>
        <el-table-column label="昵称" prop="nickname" align="center" width="200" />
        <el-table-column label="真实姓名" prop="realname" align="center" width="200" />
        <el-table-column label="性别" align="center" width="150">
          <template slot-scope="scope">
            <div>
              {{ scope.row.sex == 0? '男': '女' }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="电话" prop="phone" align="center" width="200" />
        <el-table-column label="邮箱" prop="email" align="center" width="200" />
        <el-table-column label="生日" prop="birthday" align="center" width="200" />
        <el-table-column label="注册时间" prop="createTime" align="center" width="300" />
      </el-table>
      <div class="footer">
        <el-pagination
          :current-page.sync="page.start"
          :page-sizes="[5, 10, 20, 50]"
          :page-size="page.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalNum"
          @size-change="sizeChange"
          @current-change="currentChange"
        />
      </div>
    </el-card></div>
</template>
<script>
import { findMembersByPage } from '@/api/user/index'
export default {
  data() {
    return {
      list: [],
      page: {
        start: 1,
        limit: 10,
        totalNum: 0
      }
    }
  },
  created() {
    this.getUserList()
  },
  methods: {
    // 获取用户列表
    async getUserList() {
      const { success, data, message } = await findMembersByPage(
        this.page.start,
        this.page.limit
      )
      if (success) {
        this.list = data.rows
        this.page.totalNum = data.total
      } else {
        this.$message.error(message)
      }
    },
    sizeChange(newVal) {
      this.page.start = 1
      this.page.limit = newVal
      this.getUserList()
    },
    currentChange(newVal) {
      this.page.start = newVal
      this.getUserList()
    }
  }
}
</script>
<style lang="scss" scoped>
.user{
 margin: 30px;
 .footer{
   display: flex;
   justify-content: flex-end;
   margin-top: 30px;
 }
}
</style>
